#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include "msgq.h"
#include "tools.h"

Ctos ctos;
Stoc stoc;

void query(void)
{
	
	char path[PATH_MAX];
	sprintf(path,"%s/%u",ACC_PATH,ctos.acc.id);
	pf("查询余额：acc path:%s\n",path);
	int fd = open(path,O_RDONLY);
	
	read(fd,&ctos.acc,sizeof(ctos.acc));
	sprintf(stoc.str,"您的金额为:%f",ctos.acc.money);	
	
	// 返回查询信息
	close(fd);
	stoc_send(&stoc);
}


int main()
{
	init_msgq();
	for(;;)
	{
		ctos_recv(&ctos,TYPE_QUERY);
		stoc.type = ctos.pid;
		query();
	}
}
